package com.zhangye.test.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhangye.test.mapper.MoneyTypeMapper;
import com.zhangye.test.model.MoneyType;
import com.zhangye.test.util.PageInfo;

@Service
public class MoneyTypeService {

	@Autowired
	private MoneyTypeMapper moneyTypeMapper;
	
	
	public int insert(MoneyType mt){
		int i = moneyTypeMapper.insert(mt);
		return i;
	}
	

	public List<Map<String,Object>> selectByPage(PageInfo pageInfo, String where, String order) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("myCount", pageInfo.getCount());
		param.put("pageSize", pageInfo.getPageSize());
		param.put("page", pageInfo.getPage());
		param.put("where", where);
		param.put("order", order);
		List<Map<String, Object>> m = moneyTypeMapper.selectByPage(param);
		pageInfo.setCount(Integer.parseInt(param.get("myCount").toString()));
		return m;
	}
	
	
	public int update(MoneyType mt){
		int i = moneyTypeMapper.updateByPrimaryKey(mt);
		return i;
	}
	
	
	public MoneyType selectById(Long id){
		MoneyType mt = moneyTypeMapper.selectByPrimaryKey(id);
		return mt;
	}
	
	public MoneyType selectByWhere(String where){
		List<MoneyType> list = moneyTypeMapper.selectByWhere(where);
		if(list.size() > 0){
			return list.get(0);
		}else{
			return null;
		}
	}
}
